class FileUtils{
    read(file: File,invoke: Function){
        let reader = new FileReader();
        reader.readAsText(file,"UTF-8");
        reader.onload = function(evt:any){
            invoke(evt.target.result);
        }
    }
    dowload(fileName: string, data: any): any {
        const blob = new Blob([data], {type: 'application/octet-stream'} )
        const a = document.createElement('a')
        const herf = window.URL.createObjectURL(blob)
        a.href = herf
        a.download = decodeURI(fileName)
        document.body.append(a)
        a.click()
        document.body.removeChild(a)
        window.URL.revokeObjectURL(herf)
    }
    dowloadBolb(fileName: string, blob: Blob){
        const a = document.createElement('a')
        const herf = window.URL.createObjectURL(blob)
        a.href = herf
        a.download = decodeURI(fileName)
        document.body.append(a)
        a.click()
        document.body.removeChild(a)
        window.URL.revokeObjectURL(herf)
    }
}

const fileUtils = new FileUtils()
export {fileUtils}